<#include "../header.ftl">
<link href="${TEMPLATE_PATH}/css/user_base.css" rel="stylesheet" type="text/css" />
<link href="${TEMPLATE_PATH}/css/user.css" rel="stylesheet" type="text/css" />
<link href="${TEMPLATE_PATH}/css/user_reg.css" rel="stylesheet" type="text/css" />

<script>
function showErrors(id,errors){
	for(var name in errors){
		$.fn.tips({type:"error",content:errors[name]});
		var ele=$("input[name='"+name+"']");
		id.validator('showMsg', ele, {
		    type: "error",
		    msg: errors[name]
		});
	}
}
$(function(){
	$(".form_pass").validator(
	{
		stopOnError:true,
		theme:'yellow_right_effect',
		ignore:':hidden',
		valid:function(form)
		{
			$.fn.tips({type:'loading',content:'数据提交中'});
			$.ajax(
			{
				url:"/user/exchangeJson.json",
				type:"post",
				data:$(form).serialize(),
				dataType:"json",
				success:function(data){
					var type="warn";
					if(data.result==true)
					{
						type="ok";
						$.fn.tips({type:type,content:data.msg});
					}else
					{
						showErrors($('.form_reg'),data.errors);
					}
					if(data.result==true)
					{
						setTimeout("location.href='?'",1000);
					}
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					$.fn.tips({type:"error",content:XMLHttpRequest.responseText});
				}
			});
		}
	});
	$(".form_money_to_gold").validator(
	{
		stopOnError:true,
		theme:'yellow_right_effect',
		ignore:':hidden',
		valid:function(form)
		{
			$.fn.tips({type:'loading',content:'数据提交中'});
			$.ajax(
			{
				url:"/user/exchangeMoneyToGoldJson.json",
				type:"post",
				data:$(form).serialize(),
				dataType:"json",
				success:function(data){
					var type="warn";
					if(data.result==true)
					{
						type="ok";
						$.fn.tips({type:type,content:data.msg});
					}else
					{
						showErrors($('.form_money_to_gold'),data.errors);
					}
					if(data.result==true)
					{
						setTimeout("location.href='?'",1000);
					}
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					$.fn.tips({type:"error",content:XMLHttpRequest.responseText});
				}
			});
		}
	});
	
	$("#user_menu_04").addClass("hover");
});
</script>
 <div id="position">您所在的位置：<a href="/">首页</a> > <a href="/user/">会员中心</a></div>
  <div class="w980 mt10 mc">
        <#include "userLeft.ftl">
        <div class="right_big">
            <div class="b">
                <div class="subject">金币兑换现金</div>
                <div class="p35">
                <form class="form_pass" method="post">
                <ul id="reg">
                    <li>可用金币：<span>${SESSION_USER.userGold}</span> 元</li>
                    <li>兑换数量：<input type="text" name="input_gold" class="ip" maxlength="10" data-rule="兑换数量:required;dot;" /> 个　最低兑换数量为<span> 100 </span>个</li>
                    <dd><input type="submit" value="提交" class="bnt_blue" /></dd>
                </ul>
                </form>
                </div>
            </div>
            <div class="b">
                <div class="subject">现金兑换金币</div>
                <div class="p35">
                <form class="form_money_to_gold" method="post">
                <ul id="reg">
                    <li>可用现金：<span>${SESSION_USER.userMoney}</span> 元</li>
                    <li>兑换金额：<input type="text" name="input_money" class="ip" maxlength="10" data-rule="兑换金额:required;dot;" /> 元　最低兑换金额为<span> 100 </span>个</li>
                    <dd><input type="submit" value="提交" class="bnt_blue" /></dd>
                </ul>
                </form>
                </div>
            </div>
        </div>
</div>
    
<#include "../footer.ftl">